/**
 * 修改密码窗口
 */
DC.front.win.ModifyPasswordWin = function(params, config) {
	var mpWin = this;
	
	var modifyPassword_formPanel = new DC.front.ModifyPasswordFormPanel();
	
	DC.front.win.ModifyPasswordWin.superclass.constructor.call(this, Ext.apply({
    	id : 'modify_password_win',
    	title : 'Modify Password',
    	width : 430,
    	height : 180,
        border : true,
        bodyBorder : true,
        layout : 'fit',
        modal : true,
        closeAction : 'close',
        items :[ modifyPassword_formPanel ],
        buttons : [{
        	id : 'modify_password_win_save_btn',
			text : 'Save',
			handler :function(){
				modifyPassword_formPanel.modifyPassword();
			} 
		}, {
			text : 'Cancle',
			handler :function(){
				mpWin.close();
			} 
		}]
    }, config ||{}));
};

Ext.extend(DC.front.win.ModifyPasswordWin, Ext.Window, {
	
});

DC.front.ModifyPasswordFormPanel = function(params, config) {
	var mpfp = this;
	DC.front.ModifyPasswordFormPanel.superclass.constructor.call(this, Ext.apply({
           id : 'modifyPassword_formPanel',
           header : false,
           labelWidth : 120,
           labelAlign : 'right',
           buttonAlign : 'center',
           frame : true,
           defaultType : 'textfield',
           defaults : {
               width : 260,
               labelStyle : 'margin:5px auto'
           },
           items: [/*{
           	   xtype : 'label',
           	   id : 'modifyPassword_formPanel_tip',
           	   height : 100,
               name : 'msg',
               fieldLabel : 'Tip',
               hideLabel : true,
               text : 'modifyPassword_formPanel'
           },*/ {
           	   inputType : 'password',
           	   id : 'modifyPassword_formPanel_new_password',
           	   name : 'newPassword',
               fieldLabel: '<font color="red">*</font>New Password',
               style:'margin:5px auto',
               allowBlank: false, // 表单控件不可以为空
               blankText:"Please enter your new password.",
               minLength: 6,
               minLength: 'The length of the new password cannot be less than 6.',
               maxLength: 18,
               maxLengthText : 'The length of the new password cannot be more than 18.',
               regex : /[a-zA-Z0-9]{6,18}$/,
               regexText : 'The new password is Illegal.'
           }, {
           	   inputType: 'password',
           	   id: 'modifyPassword_formPanel_ok_password',
               name: 'okPassword',
               fieldLabel: '<font color="red">*</font> Re-enter Password',
               style:'margin:5px auto',
               allowBlank: false, // 表单控件不可以为空
               blankText:"Please enter your new password again.",
               minLength: 6,
               minLength: 'The length of the re-enter password cannot be less than 6.',
               maxLength: 18,
               maxLengthText : 'The length of the re-enter password cannot be more than 18.',
               regex : /^[a-zA-Z0-9]{6,18}$/,
               regexText : 'The re-enter password is Illegal.'
           }, {
           	   inputType: 'password',
           	   id: 'modifyPassword_formPanel_old_password',
           	   name: 'oldPassword',
               fieldLabel: '<font color="red">*</font>Old Password',
               style:'margin:5px auto',
               allowBlank: false, // 表单控件不可以为空
               blankText:"Please enter your old password.",
               minLength: 6,
               minLength: 'The length of the old password cannot be less than 6.',
               maxLength: 18,
               maxLengthText : 'The length of the old password cannot be more than 18.',
               regex : /^[a-zA-Z0-9]{6,18}$/,
               regexText : 'The old password is Illegal.' 
           }]
   }, config ||{}));
};

Ext.extend(DC.front.ModifyPasswordFormPanel, Ext.form.FormPanel, {
	 // 添加用户的响应事件
	modifyPassword: function() {
   	   // 判断两次输入的密码是否相等
		var newPassVal = Ext.getCmp("modifyPassword_formPanel_new_password").getValue().trim();
		var okPassVal = Ext.getCmp("modifyPassword_formPanel_ok_password").getValue().trim();
		if(newPassVal != null && okPassVal != null && newPassVal != okPassVal){
		    Ext.getCmp("modifyPassword_formPanel_ok_password").setValue('');
		    Ext.example.msg('Prompt', 'Two of the input password is not the same.', 'warning');
			return ;
		}

		if (this.getForm().isValid()) {
			DC.util.CommonAction.loadMask("Saving...");
			this.getForm().submit({
		           clientValidation: true,
		           method: 'post',
		           url: DC.url.MODIFYPASSWORD,
		           success: function(form, action){
	                	DC.util.CommonAction.unMask();
	                	var res = action.result;
                		DC.action.SysAction.initUserInfo(res.user);
                		DC.obj.editor_tabPanel.get
                		Ext.getCmp("modify_password_win").close();
                		Ext.example.msg('Prompt', res.msg, 'prompt');
		           },
		           failure: function(form, action){
		        	   DC.util.CommonAction.unMask();
		               switch (action.failureType) {
			                case Ext.form.Action.CLIENT_INVALID: // 当客户端验证失败时执行
			                     break;
			                case Ext.form.Action.CONNECT_FAILURE:
			                	 Ext.example.msg('Prompt Win', 'Network connection failure, so fail to commit.', 'error');
			                     break;
			                case Ext.form.Action.SERVER_INVALID: // 当服务器端的success属性的值返回false时执行
			                	 Ext.example.msg('Prompt Win', action.result.msg, action.result.type);
			           }
		           }
		     });
		}
   },
   cleanAllInput : function() {
	   Ext.getCmp("modifyPassword_formPanel_new_password").setValue('');
	   Ext.getCmp("modifyPassword_formPanel_ok_password").setValue('');
	   Ext.getCmp("modifyPassword_formPanel_old_password").setValue('');
   }
});